package com.atguigu.redis_springboot.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: ..
 * @author: 杨扬
 * @create: 2022-12-27 21:28
 **/
@RestController
@RequestMapping("/redisTest")//访问路径：localhost:8080/redisTest
public class RedisTestController {

    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping
    public String testRedis() {
        //设置值到redis
        redisTemplate.opsForValue().set("name", "zhangsan");
        //从redis中获取值
        return (String)redisTemplate.opsForValue().get("name");

    }

}
